<template>
	<view class="reception">
		<nav-bar />
		<view class="title">会员接待</view>
		<view class="input">
			<input type="number" placeholder="请输入会员手机号" maxlength="11" v-model="phone">
			<u-icon name="scan" size="41" color="#333333" @click="scanCode"></u-icon>
		</view>
		<view class="confirm" @click="confirm">确认信息</view>
	</view>
</template>

<script>
	import {
		customerInfoApi
	} from "@/api/store.js"
	export default {
		data() {
			return {
				phone: '',
				type: 1
			}
		},
		onLoad(opt) {
			this.type = opt.type || 1
		},
		methods: {
			async confirm() {
				if (!this.phone) return this.$utils.toast('请输入会员手机号')
				let {
					data
				} = await customerInfoApi({
					phone: this.phone
				})
				this.$Router.push(`/pages/store/order-entry/order-entry?type=${this.type}&&uid=${data.id}`)
			},
			scanCode() {
				uni.scanCode({
					success: (res) => {
						try {
							let resp = JSON.parse(res.result)
							if(resp.type === 1){
								let data = resp.data
								this.$Router.push(
									`/pages/store/order-entry/order-entry?type=${this.type}&&uid=${data.user_id}`
									)
							}
							
						} catch (err) {
							this.$utils.toast('二维码错误')
						}
					},
					fail: (err) => {
						this.$utils.toast('二维码错误')
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	@import 'index.scss';
</style>
